/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare.data');

(function () {
	/**
	 * @class BaseVehicle
	 * BaseVehicle is a wrapper around the the server's JSON object and converts the coommon competitors list into an Ext.util.MixedCollection
	 * @namespace net.autodata.compare.data
	 */
	var BaseVehicle = function (vehicle) 
	{
		//TODO switch the common competitors from a mixed collection to a imutable mixed collection(?)
		var commonCompetitors = new Ext.util.MixedCollection(false, function (o) { 
			return o.acode;
		});
		commonCompetitors.addAll(vehicle.commonCompetitors);
		
		delete vehicle.commonCompetitors;
		
		
		//Convert the colours list to a MixedCollection
		var exteriorColours = new Ext.util.MixedCollection(false, function (o) { return o.rgb; });
		exteriorColours.addAll(vehicle.exteriorColours);
		delete vehicle.exteriorColours;
		
		return Ext.apply(vehicle, {
			
			/**
			 * @property acode
			 * @type String
			 */
			
			/**
			 * @property modelYear
			 * @type net.autodata.modelwalk.modelYear
			 */
			
			/**
			 * @property make
			 * @type net.autodata.modelwalk.Make
			 */
			
			/**
			 * @property model
			 * @type net.autodata.modelwalk.Model
			 */
			
			/**
			 * @property trim
			 * @type net.autodata.modelwalk.trim
			 */
			
			/**
			 * IOF Image Name
			 * @property imageName
			 * @type String
			 */
			
			/**
			 * @property selectedImageName
			 * @type String
			 */
			
			/**
			 * @property msrp
			 * @type float
			 */
			
			/**
			 * @property commonCompetitors
			 * @type Ext.util.MixedCollection
			 */
			commonCompetitors: commonCompetitors,
			
			/**
			 * @property exteriorColours
			 * @type Ext.util.MixedCollection
			 */
			exteriorColours: exteriorColours,
			
			getSelectedSwatch: function ()
			{
				var index = exteriorColours.findIndex('selected', true);
				return index > -1 ? exteriorColours.get(index) : undefined;
			}
			
		});
	}
	
	net.autodata.compare.data.BaseVehicle = BaseVehicle;	
})();